#ifndef __COMM_H__
#define __COMM_H__
#include "rtthread.h"
#include "stdio.h"

typedef struct 
{
	float ADC_OLD_Value;        //adc老的值
	float P_k1_k1;              
	float Q;                    //= 0.0001; 过程噪声协方差，
	float R;                    //= 5; 观察噪声协方差，
	float Kg;                   // = 0; 卡尔曼增益
	float P_k_k1;               // = 1;
  float kalman_adc_old;       //=0;
	char initFlag;
}kalmanFilterDef;//卡尔曼滤波器

void little16_to_str(rt_uint16_t value,rt_uint8_t *str);
void uint16_to_str(rt_uint16_t value,rt_uint8_t *str);
void uint32_to_str(rt_uint32_t value,rt_uint8_t *str);
rt_uint16_t str_to_uint16(rt_uint8_t *str);
rt_uint16_t str_to_little16(rt_uint8_t *str);
void show_hex_string(rt_uint8_t *str,rt_uint16_t size);
rt_uint32_t str_to_uint32(rt_uint8_t *str);
void show_int_string(rt_uint8_t *str,rt_uint16_t size);
rt_uint16_t net_crc16(rt_uint8_t *buf, rt_uint16_t len);
rt_uint8_t fun_check_sum(rt_uint8_t *i,rt_uint8_t ln);
rt_uint8_t avd_check_sum(rt_uint8_t *i,rt_uint8_t ln);
rt_uint32_t time_to_sec(rt_uint8_t hour,rt_uint8_t min,rt_uint8_t sec);

void little16_to_str(rt_uint16_t value,rt_uint8_t *str);

rt_uint16_t CRC16_CCITT(rt_uint8_t *puchMsg, rt_uint16_t usDataLen);
rt_uint16_t CRC16_CCITT_FALSE(rt_uint8_t *puchMsg, rt_uint16_t usDataLen);
rt_uint16_t CRC16_XMODEM(rt_uint8_t *puchMsg, rt_uint16_t usDataLen);
rt_uint16_t CRC16_X25(rt_uint8_t *puchMsg, rt_uint16_t usDataLen);
rt_uint16_t CRC16_MODBUS(rt_uint8_t *puchMsg, rt_uint16_t usDataLen);
rt_uint16_t CRC16_IBM(rt_uint8_t *puchMsg, rt_uint16_t usDataLen);
rt_uint16_t CRC16_MAXIM(rt_uint8_t *puchMsg, rt_uint16_t usDataLen);
rt_uint16_t CRC16_USB(rt_uint8_t *puchMsg, rt_uint16_t usDataLen);

unsigned long kalman_filter(kalmanFilterDef *filter, unsigned long ADC_Value,float Q);

rt_uint16_t string02_to_hex(rt_uint8_t *buf,rt_uint8_t *hex);
void hex_to_string02(rt_uint8_t *hex,rt_uint16_t size,rt_uint8_t *str);
void string02_del_space(rt_uint8_t *str);

void show_ch_string(rt_uint8_t *str,rt_uint16_t size);


void generateRandomString(int length,char *randomString);

#endif

